import { deleteYxryApi } from "@/api/yxry"
import { YxryModel } from "@/api/yxry/YxryModel"
import useInstance from "@/hooks/useInstance"
import { EditType, FuncList } from "@/type/BaseType"
import { ElMessage } from "element-plus"
import { ref } from "vue"


export default function useYxry(getList:FuncList) {
    const addRef = ref<{ show: (type: string, row?: YxryModel) => void }>()
    const { global } = useInstance();
    
    const addBtn = () => {
        
        addRef.value?.show(EditType.ADD)
    }
    
    const editBtn = (row: YxryModel) => {
        console.log(row)
        addRef.value?.show(EditType.EDIT, row)
    }
    
    const deleteBtn = async(row:YxryModel) => {
        let confirm=await global.$ConfirmUtil('确定删除该数据吗')
        if (confirm) {
            let res = await deleteYxryApi(row.id)
            if (res && res.code == 200) {
                ElMessage.success(res.msg)
                
                getList()
            }
        }
    }

    return {
        addBtn,
        deleteBtn,
        editBtn,
        addRef
    }
}